package com.example.tuter.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tuter.R;
import com.example.tuter.entity.Post;

public class ReactAdapter extends RecyclerView.Adapter<ReactAdapter.ReactViewHolder> {

    private Post data;
    private Context context;
    private final int TYPE_ITEM=1;
    public ReactAdapter(Post data, Context context) {
        this.data=data;
        this.context=context;
    }

    @NonNull
    @Override
    public ReactViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notification,parent,false);
        return new ReactViewHolder(view,viewType);
    }

    @Override
    public void onBindViewHolder(@NonNull ReactViewHolder holder, int position) {
        if (getItemViewType(position)==TYPE_ITEM) {
            holder.username.setText(data.getUsername());
            holder.likes.setText(data.getLikes());
            holder.comments.setText(data.getFloors());
            holder.description.setText(data.getDescription());
            holder.title.setText(data.getTitle());
        }

    }

    @Override
    public int getItemCount() {
        return 1;
    }
    @Override
    public int getItemViewType(int position) {
        return TYPE_ITEM;
    }

    public class ReactViewHolder extends RecyclerView.ViewHolder {
        private TextView username;
        private TextView title;
        private TextView description;
        private TextView comments;
        private TextView likes;
        private TextView academyName;
        private ImageView pic1;
        private TextView createTime;
        public ReactViewHolder(@NonNull View itemView,int viewType) {
            super(itemView);
            username=itemView.findViewById(R.id.react_username);
            title=itemView.findViewById(R.id.react_title);
            description=itemView.findViewById(R.id.react_description);
            comments=itemView.findViewById(R.id.react_comment_number_num);
            likes=itemView.findViewById(R.id.react_comment_likes_num);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (monItemClickListener!=null){
                        monItemClickListener.onRecyclerItemClick(getAdapterPosition());
                    }
                }
            });
        }

    }
    private  OnRecyclerItemClickListener monItemClickListener;

    public void setRecyclerItemClickListener(OnRecyclerItemClickListener listener){
        monItemClickListener=listener;
    }
    public interface OnRecyclerItemClickListener{
        void onRecyclerItemClick(int position);
    }
}
